#include <iostream>
#include <string>
#include <cstdio>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>

int main()
{
    std::size_t size_  = atoi(getenv("Content-Length"));    
    std::string pragam_;
    char c;

    while(size_)
    {
        read(0, &c, 1);
        size_--;
        pragam_ += c;
    }
    std::cout<<"pragam_:["<<pragam_<<"]\n";

    char name[30] = {0};
    char gender[10] = {0};
    char email[25] = {0};
    char id[18] = {0};
    char password[18] = {0};


    sscanf(pragam_.c_str(), "name=%s&gender=%s&email=%s&id=%s&password=%s", name, gender, email, id, password);

    std::cout<<"id:["<<id<<"]\n";

    char msg[1024] = {0};
    sprintf(msg, "name = %s\ngender = %s\nemail = %s\nid = %s\npassword = %s\n", name, gender, email, id, password);
    
    int fd = open("subinmsg.txt", O_WRONLY|O_CREAT);
    if(write(fd, msg, 1023)){
        std::cout<<"SUCCESS"<<std::endl;
    }
    else
    {
        std::cout<<"FAILD"<<std::endl;
    }
    close(fd);
    return 0;
}
